//
//  LGReceptionSettingController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/30.
//  接诊设置

#import "LGReceptionSettingController.h"
//排班设置
#import "LGSchedulHomeController.h"
//临时停诊
#import "LGTemporaryStopController.h"
@interface LGReceptionSettingController ()<UIScrollViewDelegate>
/**   */
@property (nonatomic , strong)LGSchedulHomeController *schedulVC;
/**   */
@property (nonatomic , strong)LGTemporaryStopController *stopVC;
/**   */
@property (nonatomic , strong)UIScrollView *scrollView;
/**   */
@property (nonatomic , strong)UIButton *schedulBtn;
/**   */
@property (nonatomic , strong)UIButton *stopButton;
/**   */
@property (nonatomic , strong)UIView *topView;

@end

@implementation LGReceptionSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"接诊设置";
    self.view.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self addChildViewController:self.schedulVC];
    [self addChildViewController:self.stopVC];
    [self.view addSubview:self.topView];
    [self.topView addSubview:self.schedulBtn];
    [self.topView addSubview:self.stopButton];
    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.schedulVC.view];
    [self.scrollView addSubview:self.stopVC.view];
}

-(void)itemTouchedAction:(UIButton *)sender{
    sender.selected = YES;
    sender.titleLabel.font = LGFontWeight(15, UIFontWeightMedium);
    if(sender == self.schedulBtn){
        self.stopButton.selected = NO;
        self.stopButton.titleLabel.font = LGFont(14);
        [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    }else{
        self.schedulBtn.selected = NO;
        self.schedulBtn.titleLabel.font = LGFont(14);
        [self.scrollView setContentOffset:CGPointMake(Screen_W, 0) animated:YES];
        [self.stopVC requestData];
    }
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSInteger count = scrollView.contentOffset.x/Screen_W;
    self.schedulBtn.selected = (count == 0)?YES:NO;
    self.stopButton.selected = (count == 1)?YES:NO;
    if(count == 1){
        [self.stopVC requestData];
    }
    
}

#pragma mark
#pragma mark ====> 创建控件
-(LGSchedulHomeController *)schedulVC{
    if(!_schedulVC){
        _schedulVC = [[LGSchedulHomeController alloc] init];
        _schedulVC.view.frame = CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight-viewPix(44));
    }
    return _schedulVC;
}

-(LGTemporaryStopController *)stopVC{
    if(!_stopVC){
        _stopVC = [[LGTemporaryStopController alloc] init];
        _stopVC.view.frame = CGRectMake(Screen_W, 0, Screen_W, Screen_H-topBarHeight-viewPix(44));
    }
    return _stopVC;
}

-(UIScrollView *)scrollView{
    if(!_scrollView){
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, viewPix(44), Screen_W, Screen_H-topBarHeight-viewPix(44))];
        _scrollView.contentSize = CGSizeMake(Screen_W*2, Screen_H-topBarHeight-viewPix(44));
        _scrollView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        _scrollView.pagingEnabled = YES;
        _scrollView.delegate = self;
    }
    return _scrollView;
}

-(UIView *)topView{
    if(!_topView){
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(44))];
        _topView.backgroundColor = [UIColor whiteColor];
    }
    return _topView;
}

-(UIButton *)schedulBtn{
    if(!_schedulBtn){
        _schedulBtn = [UIButton buttonWithTitle:@"排班设置" titleFont:LGFontWeight(15, UIFontWeightMedium) normalColor:@"#666666" selectColor:@"#4C87FD"];
        _schedulBtn.frame = CGRectMake(viewPix(32), viewPix(6), viewPix(140), viewPix(32));
        [_schedulBtn setBackgroundColor:[UIColor colorWithString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_schedulBtn setBackgroundColor:[UIColor colorWithString:@"#EAF4FF"] forState:UIControlStateSelected];
        [_schedulBtn setBackgroundColor:[UIColor colorWithString:@"#EAF4FF"] forState:UIControlStateHighlighted];
        _schedulBtn.cornerRidus = viewPix(16);
        _schedulBtn.selected = YES;
        [_schedulBtn addTarget:self action:@selector(itemTouchedAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _schedulBtn;
}

-(UIButton *)stopButton{
    if(!_stopButton){
        _stopButton = [UIButton buttonWithTitle:@"临时停诊" titleFont:LGFontWeight(15, UIFontWeightMedium) normalColor:@"#666666" selectColor:@"#4C87FD"];
        _stopButton.frame = CGRectMake(Screen_W-viewPix(172), viewPix(6), viewPix(140), viewPix(32));
        [_stopButton setBackgroundColor:[UIColor colorWithString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_stopButton setBackgroundColor:[UIColor colorWithString:@"#EAF4FF"] forState:UIControlStateSelected];
        [_stopButton setBackgroundColor:[UIColor colorWithString:@"#EAF4FF"] forState:UIControlStateHighlighted];
        _stopButton.cornerRidus = viewPix(16);
        [_stopButton addTarget:self action:@selector(itemTouchedAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _stopButton;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
